Gitlab Create MR Comment Tool
Add comments to merge requests in GitLab projects to streamline code review and collaboration. Specify project ID, merge request ID, and comment content for effective feedback.
Instructions
为指定项目的合并请求添加评论。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| comment | Yes | 评论内容 | |
| fields | No | 需要返回的字段路径数组 | |
| mergeRequestId | Yes | 合并请求 ID | |
| projectId | Yes | 项目 ID |
Implementation Reference
- The `execute` method implementing the tool's core logic: resolves project ID, makes POST request to GitLab API to create MR comment, filters response if fields specified, handles errors.async execute(args: unknown, context: Context<Record<string, unknown> | undefined>) { const typedArgs = args as { projectId: string | number; mergeRequestId: number; comment: string; fields?: string[]; }; const { projectId: projectIdOrName, mergeRequestId, comment, fields } = typedArgs; try { const client = createGitlabClientFromContext(context); const resolvedProjectId = await client.resolveProjectId(projectIdOrName); if (!resolvedProjectId) { throw new Error(`无法解析项目 ID 或名称:${projectIdOrName}`); } const endpoint = `/projects/${encodeURIComponent(String(resolvedProjectId))}/merge_requests/${mergeRequestId}/notes`; const response = await client.apiRequest(endpoint, "POST", undefined, { body: comment }); if (!client.isValidResponse(response)) { throw new Error(`GitLab API error: ${response?.message || 'Unknown error'}`); } if (fields) { const filteredResponse = filterResponseFields(response, fields); return { content: [{ type: "text", text: JSON.stringify(filteredResponse) }] } as ContentResult; } return { content: [{ type: "text", text: JSON.stringify(response) }] } as ContentResult; } catch (error: any) { return { content: [ { type: "text", text: `GitLab MCP 工具调用异常:${error?.message || String(error)}` } ], isError: true }; } }
- Zod schema defining the input parameters: projectId (string|number), mergeRequestId (number), comment (string), optional fields (string[]).parameters: z.object({ projectId: z.union([z.string(), z.number()]).describe("项目 ID 或名称"), mergeRequestId: z.number().describe("合并请求 ID"), comment: z.string().describe("评论内容"), fields: z.array(z.string()).optional().describe("需要返回的字段路径数组"), }),
- src/gitlab-tools-sdk.ts:71-80 (registration)The `fastmcpTools` array including GitlabCreateMRCommentTool, used for registration.const fastmcpTools = [ GitlabAcceptMRTool, GitlabCreateMRCommentTool, GitlabCreateMRTool, GitlabGetUserTasksTool, GitlabRawApiTool, GitlabSearchProjectDetailsTool, GitlabSearchUserProjectsTool, GitlabUpdateMRTool, ];
- src/gitlab-tools-sdk.ts:142-148 (registration)The registration loop in `registerGitLabToolsForFastMCP` that calls `server.addTool(tool)` for filtered tools.fastmcpTools.forEach(tool => { const standardizedName = toolNameMapping[tool.name as keyof typeof toolNameMapping]; if (shouldRegisterTool(standardizedName as GitLabToolName, options.toolFilter)) { // GitLabTool is now fully compatible with FastMCP's base type, can be registered directly server.addTool(tool); } });
- src/gitlab-tools-sdk.ts:64-64 (registration)Tool name mapping from internal name to standardized name used in filtering.[GitlabCreateMRCommentTool.name]: "Gitlab_Create_MR_Comment_Tool",